Workflow
Part 2, Chapter 17
Reference guide.
Alias
To save some precious keystrokes, let's create an alias for the docker-compose command -- dc.
Simply add the following line to your .bashrc file:
alias dc='docker-compose'
Save the file, then execute it:
$ source ~/.bashrc
Test it out!
On Windows? You will first need to create a PowerShell Profile (if you don't already have one), and then you can add the alias to it using Set-Alias:
Set-Alias dc docker-compose.
Common Commands
Build the images:
$ docker-compose build
Run the containers:
$ docker-compose up -d
Apply the migrations:
$ docker-compose exec web aerich upgrade
# prefer just to apply the latest changes to the database, without the migrations?
# $ docker-compose exec web python app/db.py
Run the tests:
$ docker-compose exec web python -m pytest
Run the tests with coverage:
$ docker-compose exec web python -m pytest --cov="."
Lint:
$ docker-compose exec web flake8 .
Run Black and isort with check options:
$ docker-compose exec web black . --check
$ docker-compose exec web isort . --check-only
Make code changes with Black and isort:
$ docker-compose exec web black .
$ docker-compose exec web isort .
Other Commands
To stop the containers:
$ docker-compose stop
To bring down the containers:
$ docker-compose down
Want to force a build?
$ docker-compose build --no-cache
Remove images:
$ docker rmi $(docker images -q)
Postgres
Want to access the database via psql?
$ docker-compose exec web-db psql -U postgres
Then, you can connect to the database and run SQL queries. For example:
# \c web_dev
# select * from textsummary;
✓ Mark as Completed